//
//  BuyWebViewController.m
//  GoShops
//
//  Created by zcj on 15-11-30.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "BuyWebViewController.h"
#import "Grouble.h"
#import "MBProgressHUD+MJ.h"
#import "GetUrlString.h"



@interface BuyWebViewController ()<UIWebViewDelegate>

@end

@implementation BuyWebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
        // Custom initialization
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    for (UIView *child in
//         self.navigationController.tabBarController.tabBar.subviews) {
//        if ([child isKindOfClass:[UIControl class]]) {
//            [child removeFromSuperview];
//        }
//    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNav];
    [self initViews];
    // Do any additional setup after loading the view.
}
- (void)setNav
{
    //返回
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 23, 23);
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(OnBackBtn:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
}
- (void)OnBackBtn:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)initViews
{
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    self.webView.delegate = self;
    self.webView.scalesPageToFit = YES;
    [self.view addSubview:self.webView];
    
    NSString * urlStr = [[GetUrlString sharedManager]urlWithRushBuyWebData];
    NSLog(@"%@",urlStr);
    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
    [self.webView loadRequest:request];
    
    
    _activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(ScreenWidth/2-15, ScreenHeight/2-15, 30, 30)];
    _activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    _activityView.hidesWhenStopped = YES;
    [self.view addSubview:_activityView];
    [self.view bringSubviewToFront:_activityView];
}
#pragma mark - 正在加载的时候
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [MBProgressHUD showMessage:@"正在加载"];
}
#pragma mark - 加载完成的时候
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUD];
    NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    ZCJLog(@"%@",theTitle);
    self.title = theTitle;
    [_activityView stopAnimating];
}
#pragma mark - 开始加载
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    [_activityView startAnimating];
    return YES;
}
#pragma mark - 加载失败的时候
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [MBProgressHUD showError:@"加载失败"];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
